<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是如何在Windows下将自己的Hexo静态博客部署到云服务器上去的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV05-部署云服务器-02-部署网站">
<meta property="og:url" content="https://sumumm.github.io/post/beeb17ce.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是如何在Windows下将自己的Hexo静态博客部署到云服务器上去的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612083632267.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612083942156.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612085849416.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612085956144.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612090154862.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612090519902.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612090709461.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612090957409.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612092141913.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612161436628.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612161724110.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612162632908.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612162742024.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612163221518.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612163850916.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612164026730.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612164951206.png">
<meta property="article:published_time" content="2023-07-02T08:17:11.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.074Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="博客搭建">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612083632267.png">


<link rel="canonical" href="https://sumumm.github.io/post/beeb17ce.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/beeb17ce.html","path":"post/beeb17ce.html","title":"LV05-部署云服务器-02-部署网站"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV05-部署云服务器-02-部署网站 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81Windows%E6%9C%AC%E5%9C%B0%E7%AB%AF"><span class="nav-text">一、Windows本地端</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-Git%E5%AE%89%E8%A3%85%E4%B8%8E%E5%9F%BA%E6%9C%AC%E9%85%8D%E7%BD%AE"><span class="nav-text">1. Git安装与基本配置</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E5%AE%89%E8%A3%85"><span class="nav-text">1. 安装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-%E9%85%8D%E7%BD%AE"><span class="nav-text">2. 配置</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-SSH%E7%94%9F%E6%88%90%E5%85%AC%E9%92%A5"><span class="nav-text">2. SSH生成公钥</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E5%AE%9D%E5%A1%94%E9%9D%A2%E6%9D%BF"><span class="nav-text">二、宝塔面板</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%AE%9D%E5%A1%94%E9%9D%A2%E6%9D%BF%E7%AE%80%E4%BB%8B"><span class="nav-text">1. 宝塔面板简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%AE%9D%E5%A1%94%E9%9D%A2%E6%9D%BF%E5%AE%89%E8%A3%85"><span class="nav-text">2. 宝塔面板安装</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E5%AE%89%E8%A3%85%E5%91%BD%E4%BB%A4%E8%8E%B7%E5%8F%96"><span class="nav-text">2.1 安装命令获取</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E5%9C%A8%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E5%AE%89%E8%A3%85"><span class="nav-text">2.2 在云服务器上安装</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%BC%80%E6%94%BE%E7%AB%AF%E5%8F%A3"><span class="nav-text">3. 云服务器开放端口</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E7%99%BB%E5%BD%95%E5%AE%9D%E5%A1%94%E9%9D%A2%E6%9D%BF"><span class="nav-text">4. 登录宝塔面板</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E5%AE%89%E8%A3%85%E5%A5%97%E4%BB%B6"><span class="nav-text">5. 安装套件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-%E5%88%9B%E5%BB%BA%E7%BD%91%E7%AB%99"><span class="nav-text">6. 创建网站</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#6-1-%E6%B7%BB%E5%8A%A0%E7%AB%99%E7%82%B9"><span class="nav-text">6.1 添加站点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-2-%E5%A1%AB%E5%86%99%E7%BD%91%E7%AB%99%E4%BF%A1%E6%81%AF"><span class="nav-text">6.2 填写网站信息</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-%E4%B8%8A%E4%BC%A0%E7%BD%91%E7%AB%99%E6%BA%90%E7%A0%81"><span class="nav-text">7. 上传网站源码</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-1-%E5%88%A0%E9%99%A4%E9%BB%98%E8%AE%A4%E7%94%9F%E6%88%90%E7%9A%84%E6%96%87%E4%BB%B6"><span class="nav-text">7.1 删除默认生成的文件</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#7-2-%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B6"><span class="nav-text">7.2 上传文件</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-IP%E8%AE%BF%E9%97%AE%E7%BD%91%E7%AB%99"><span class="nav-text">8. IP访问网站</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#9-%E5%9F%9F%E5%90%8D%E8%AE%BF%E9%97%AE%E7%BD%91%E7%AB%99"><span class="nav-text">9. 域名访问网站</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%AB%AF"><span class="nav-text">三、服务器端</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-Git%E7%9A%84%E5%AE%89%E8%A3%85"><span class="nav-text">1. Git的安装</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%B7%BB%E5%8A%A0%E6%96%B0%E7%94%A8%E6%88%B7git"><span class="nav-text">2. 添加新用户git</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E5%88%9B%E5%BB%BA%E7%94%A8%E6%88%B7"><span class="nav-text">2.1 创建用户</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E8%AE%BE%E7%BD%AEgit%E7%94%A8%E6%88%B7%E6%9D%83%E9%99%90"><span class="nav-text">2.2 设置git用户权限</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-1-sudoers%E6%96%87%E4%BB%B6"><span class="nav-text">2.2.1 sudoers文件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-2-%E4%BF%AE%E6%94%B9%E7%94%A8%E6%88%B7%E6%9D%83%E9%99%90"><span class="nav-text">2.2.2 修改用户权限</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E6%B7%BB%E5%8A%A0SSH%E5%85%AC%E9%92%A5"><span class="nav-text">3. 添加SSH公钥</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E5%88%9B%E5%BB%BAGit%E4%BB%93%E5%BA%93"><span class="nav-text">4. 创建Git仓库</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-%E5%88%9B%E5%BB%BA%E8%A3%B8%E4%BB%93%E5%BA%93"><span class="nav-text">4.1 创建裸仓库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-%E6%B7%BB%E5%8A%A0%E9%92%A9%E5%AD%90%E5%87%BD%E6%95%B0"><span class="nav-text">4.2 添加钩子函数</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E4%BF%AE%E6%94%B9%E7%9B%B8%E5%85%B3%E6%96%87%E4%BB%B6%E6%9D%83%E9%99%90"><span class="nav-text">5. 修改相关文件权限</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#5-1-%E4%BF%AE%E6%94%B9%E9%92%A9%E5%AD%90%E5%87%BD%E6%95%B0%E6%9D%83%E9%99%90"><span class="nav-text">5.1 修改钩子函数权限</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-2-%E4%BF%AE%E6%94%B9%E8%A3%B8%E4%BB%93%E5%BA%93%E6%9D%83%E9%99%90"><span class="nav-text">5.2 修改裸仓库权限</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-3-%E4%BF%AE%E6%94%B9%E7%BD%91%E7%AB%99%E6%A0%B9%E7%9B%AE%E5%BD%95%E6%9D%83%E9%99%90"><span class="nav-text">5.3 修改网站根目录权限</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-%E6%B5%8B%E8%AF%95%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E6%8B%89%E5%8F%96%E8%A3%B8%E4%BB%93%E5%BA%93"><span class="nav-text">6. 测试是否可以拉取裸仓库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-%E6%8E%A8%E9%80%81%E6%96%87%E4%BB%B6"><span class="nav-text">7. 推送文件</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9B%9B%E3%80%81Hexo%E7%AB%99%E7%82%B9%E7%9A%84%E9%85%8D%E7%BD%AE"><span class="nav-text">四、Hexo站点的配置</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%AE%89%E8%A3%85%E4%B8%80%E9%94%AE%E9%83%A8%E7%BD%B2%E5%B7%A5%E5%85%B7"><span class="nav-text">1. 安装一键部署工具</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E9%85%8D%E7%BD%AE%E7%AB%99%E7%82%B9%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="nav-text">2. 配置站点配置文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E4%B8%80%E9%94%AE%E9%83%A8%E7%BD%B2"><span class="nav-text">3. 一键部署</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%94%E3%80%81%E6%95%88%E6%9E%9C%E9%A2%84%E8%A7%88"><span class="nav-text">五、效果预览</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/beeb17ce.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV05-部署云服务器-02-部署网站 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV05-部署云服务器-02-部署网站
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-07-02 16:17:11" itemprop="dateCreated datePublished" datetime="2023-07-02T16:17:11+08:00">2023-07-02</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" itemprop="url" rel="index"><span itemprop="name">博客搭建</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>6.8k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>25 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是如何在<code>Windows</code>下将自己的<code>Hexo</code>静态博客部署到云服务器上去的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr><td align="center" width=150px>Windows  </td><td align="left">Win11</td></tr>    <tr><td align="center" width=150px>Git</td><td align="left">Version 3.5.2 (Windows版本) </td></tr>    <tr><td align="center" width=150px>云服务器 </td><td align="left">腾讯轻量级云服务器，配置为CPU: 2核 内存: 2GB SSD：40GB 系统为Ubuntu20.04-64位</td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr><td align="center">参考方向  </td><td align="center">参考原文</td></tr>    <tr><td align="left">---</td><td align="left"><a href="" target="_blank">--- <i class="fa fa-external-link-alt"></i> </a></td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">---</td>        <td align="left">--- <a href="" target="_blank">  <i class="fa fa-external-link-alt"></i></a></td>      </tr></table>
              </div>
            </details>

<h1 id="一、Windows本地端"><a href="#一、Windows本地端" class="headerlink" title="一、Windows本地端"></a><font size=3>一、<code>Windows</code>本地端</font></h1><h2 id="1-Git安装与基本配置"><a href="#1-Git安装与基本配置" class="headerlink" title="1. Git安装与基本配置"></a><font size=3>1. <code>Git</code>安装与基本配置</font></h2><h3 id="1-安装"><a href="#1-安装" class="headerlink" title="1. 安装"></a><font size=3>1. 安装</font></h3><ul>
<li><code>git</code>官网</li>
</ul>
<p><code>git</code>官网地址：<a href="https://git-scm.com/" target="_blank"><code>git</code>官网 <i class="fa fa-external-link-alt"></i></a></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https://git-scm.com/</span><br></pre></td></tr></table></figure>

<p>我们直接在<code>Git</code>官网的<code>Download</code>页面下载符合自己<code>Windows</code>的版本即可，然后进行安装就可以了，这个安装过程嘛，这里就不写了，就是一直下一步就完了，我是这样的，正常使用，没有问题的。</p>
<h3 id="2-配置"><a href="#2-配置" class="headerlink" title="2. 配置"></a><font size=3>2. 配置</font></h3><p>其实简单来说只需要配置以下两项就足够使用啦。</p>
<ul>
<li>对<code>commit</code>操作设置关联的用户名</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.name &quot;[name]&quot;</span><br></pre></td></tr></table></figure>

<ul>
<li>对commit操作设置关联的邮箱地址</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.email &quot;[email address]&quot;</span><br></pre></td></tr></table></figure>

<h2 id="2-SSH生成公钥"><a href="#2-SSH生成公钥" class="headerlink" title="2. SSH生成公钥"></a><font size=3>2. <code>SSH</code>生成公钥</font></h2><p>可以先查看一下自己的电脑中是否已经生成过<code>SSH</code>私钥和公钥，我们打开<code>Git Bash</code>，然后输入以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ls ~/.ssh</span><br></pre></td></tr></table></figure>

<p>然后就可以查看自己电脑中是否有<code>SSH</code>公钥和私钥了，我是之前使用过，所以有私钥文件<code>id_rsa</code>和公钥文件<code>id_rsa.pub</code>：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">id_rsa  id_rsa.pub  known_hosts  known_hosts.old</span><br></pre></td></tr></table></figure>

<p>若是提示<code>.ssh</code>目录不存在，或者是<code>ls</code>之后什么也没有，那这个时候就需要生成<code>SSH</code>私钥啦，我们可以输入以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t rsa -C &quot;user&#x27;s email address&quot;</span><br></pre></td></tr></table></figure>

<details class="folding-tag" blue><summary> 点击查看参数解释 </summary>
              <div class='content'>
              <ul><li><p><code>-t</code> 指定密钥类型，默认是 <code>rsa</code> ，可以省略 ;</p></li><li><p><code>-C</code> 用于识别这个密钥的注释，可以输入任何内容 ;</p></li></ul>
              </div>
            </details>

<p>这里的<code>user&#39;s email address</code>好像并没有什么限制，我在<code>Git</code>官方说明文档上看到，其实我们不需要输入邮箱也可以，也可以使用下边的命令生成相应的公钥和私钥文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -o</span><br></pre></td></tr></table></figure>

<p>然后我们一路默认就可以啦，期间会有一次让输入<code>passphrase</code>输入完后还会让确认<code>passphrase</code>，这个好像是一个密码之类的，为了方便，我一直都是没有填写<code>passphrase</code>的，直接<code>enter</code>过去。</p>
<p>生成后，我们就可以在<code>~/.ssh</code>文件目录下看到上边的两个文件啦，该目录在<code>Win</code>下的绝对路径是<code>C:\Users\用户名\.ssh</code>。</p>
<h1 id="二、宝塔面板"><a href="#二、宝塔面板" class="headerlink" title="二、宝塔面板"></a><font size=3>二、宝塔面板</font></h1><p>按照宝塔面板的目的就是，部署网站，让我们可以通过域名或者<code>IP</code>地址访问到我们的网站。</p>
<h2 id="1-宝塔面板简介"><a href="#1-宝塔面板简介" class="headerlink" title="1. 宝塔面板简介"></a><font size=3>1. 宝塔面板简介</font></h2><p>宝塔面板是一款安全高效的服务器运维面板，可以用于管理、维护服务器，也就是可以通过浏览器管理服务器，例如创建新网站、<code>FTP</code>、数据库等。宝塔面板官网地址：<a href="https://www.bt.cn/new/index.html" target="_blank">宝塔面板 <i class="fa fa-external-link-alt"></i></a></p>
<h2 id="2-宝塔面板安装"><a href="#2-宝塔面板安装" class="headerlink" title="2. 宝塔面板安装"></a><font size=3>2. 宝塔面板安装</font></h2><h3 id="2-1-安装命令获取"><a href="#2-1-安装命令获取" class="headerlink" title="2.1 安装命令获取"></a><font size=3>2.1 安装命令获取</font></h3><p>我们可以在这里找到如何安装宝塔面板：<a target="_blank" rel="noopener" href="https://www.bt.cn/new/download.html">宝塔面板下载，免费全能的服务器运维软件 (bt.cn) <i class="fa fa-external-link-alt"></i> </a></p>
<p>它有两种安装方式，脚本安装和在线安装，个人觉得在线安装好麻烦，还要登陆<code>SSH</code>验证之类的，我就选择脚本安装啦。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612083632267.png" alt="image-20220612083632267" style="zoom:50%;" />

<p>由于我的服务器是<code>Ubuntu20.04</code>系统的，所以按要求选择相应的命令即可：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612083942156.png" alt="image-20220612083942156" style="zoom:50%;" />

<h3 id="2-2-在云服务器上安装"><a href="#2-2-在云服务器上安装" class="headerlink" title="2.2 在云服务器上安装"></a><font size=3>2.2 在云服务器上安装</font></h3><p>让我们登录自己的服务器，然后输入上边的命令，即可开始自动下载安装：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh &amp;&amp; sudo bash install.sh ed8484bec</span><br></pre></td></tr></table></figure>

<p>等待一会，就会安装完毕，安装过程中会有一次需要用户确认的选项：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Do you want to install Bt-Panel to the /www directory now?(y/n)</span><br></pre></td></tr></table></figure>

<p>然后输入<code>y</code>就可以啦，过一会安装完毕后会有如下信息提示：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">上边都是安装过程，省略了，出现下边的就是安装成功了</span></span><br><span class="line">==================================================================</span><br><span class="line">Congratulations! Installed successfully!</span><br><span class="line">==================================================================</span><br><span class="line">外网面板地址: http://xxx.xxx.xxx.xxx:8888/xxxxxxxx</span><br><span class="line">内网面板地址: http://xxx.xxx.xxx.xxx:8888/xxxxxxxx</span><br><span class="line">username: xxxxxxxx</span><br><span class="line">password: xxxxxxxx</span><br><span class="line">If you cannot access the panel,</span><br><span class="line">release the following panel port [8888] in the security group</span><br><span class="line">若无法访问面板，请检查防火墙/安全组是否有放行面板[8888]端口</span><br><span class="line">==================================================================</span><br><span class="line">Time consumed: 1 Minute!</span><br></pre></td></tr></table></figure>

<p>外网面板地址就是我们访问宝塔面板的网址，<code>username</code>就是我们登录面板的用户名，<code>password</code>就是登录宝塔面板的密码。</p>
<h2 id="3-云服务器开放端口"><a href="#3-云服务器开放端口" class="headerlink" title="3. 云服务器开放端口"></a><font size=3>3. 云服务器开放端口</font></h2><p>我们看到安装成功后，有这么一句提示：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">若无法访问面板，请检查防火墙/安全组是否有放行面板[8888]端口</span><br></pre></td></tr></table></figure>

<p>这个时候，我们可以打开我们的服务器【服务器】&rarr;【防火墙】&rarr;【添加规则】（<a target="_blank" rel="noopener" href="https://console.cloud.tencent.com/lighthouse/instance/detail?rid=4&id=lhins-0p1o1jb6&tab=firewall">服务器 - 轻量应用服务器 - 控制台 (tencent.com) <i class="fa fa-external-link-alt"></i> </a>）</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612085849416.png" alt="image-20220612085849416" style="zoom:50%;" />

<p>然后我们会看到这样一个界面：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612085956144.png" alt="image-20220612085956144" style="zoom:50%;" />

<p>（1）应用类型，选自定义就可以啦；</p>
<p>（2）协议就默认的就行；</p>
<p>（3）端口要选择<code>8888</code>；</p>
<p>（4）备注嘛，不是必须的，我们随便写就好啦</p>
<p>开放端口后，就可以在规则这里看到啦：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612090154862.png" alt="image-20220612090154862" style="zoom:50%;" />

<h2 id="4-登录宝塔面板"><a href="#4-登录宝塔面板" class="headerlink" title="4. 登录宝塔面板"></a><font size=3>4. 登录宝塔面板</font></h2><p>我们将刚才的外网面板地址复制到浏览器中打开，就可以进入登录界面了：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://xxx.xxx.xxx.xxx:8888/xxxxxxxx</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612090519902.png" alt="image-20220612090519902" style="zoom:33%;" />

<p>然后我们输入刚才的<code>username</code>和<code>password</code>登录即可，登录成功后，会提示绑定宝塔账号，自己可以去官网注册一个，然后在这一步绑定即可：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612090709461.png" alt="image-20220612090709461" style="zoom:33%;" />

<h2 id="5-安装套件"><a href="#5-安装套件" class="headerlink" title="5. 安装套件"></a><font size=3>5. 安装套件</font></h2><p>绑定完毕后会进入宝塔面板的主页，会直接弹出一个推荐安装的套件，我一般是直接选择<code>LNMP</code>套件进行安装，我也是刚开始搞这一方面，本着能用就行的思想，直接一键安装。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612090957409.png" alt="image-20220612090957409" style="zoom: 33%;" />

<p>然后等待安装完毕就好啦，安装时间比较久，这段时间其实可以去配置一下服务器。</p>
<h2 id="6-创建网站"><a href="#6-创建网站" class="headerlink" title="6. 创建网站"></a><font size=3>6. 创建网站</font></h2><h3 id="6-1-添加站点"><a href="#6-1-添加站点" class="headerlink" title="6.1 添加站点"></a><font size=3>6.1 添加站点</font></h3><p>我们选择【网站】&rarr;【PHP项目】&rarr;【添加站点】</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612092141913.png" alt="image-20220612092141913" style="zoom:50%;" />

<p>上边的三种项目有啥不同嘛，我也不是特别清楚，作为只是了解一点点前端的人来说，我只管建一个网站，能跑就行，哈哈哈，后边搞明白了再补充修改。</p>
<h3 id="6-2-填写网站信息"><a href="#6-2-填写网站信息" class="headerlink" title="6.2 填写网站信息"></a><font size=3>6.2 填写网站信息</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612161436628.png" alt="image-20220612161436628" style="zoom: 33%;" />

<p>（1）是要填写自己的域名，我的还在备案中，所以这里随便填个名称，后边根目录的名称会根据这个生成的，一定要按格式，我图中填写的后边提交的时候就会报错。</p>
<p>（2）关于根目录，它会以我们填写的域名为根目录，也就是说我们上边填的<code>name</code>，下边的根目录就会是<code>/www/wwwroot/name</code>的形式，其实根目录是可以自己指定的，也就是说，我可以把根目录除的<code>name</code>改成自己想要的名字，它上边的两级就不要改了，按照默认的话可能出错的几率小些把。比如我上边填的<code>hexo</code>，下边自动生成的根目录名称就会是<code>/www/wwwroot/hexo</code>，但是我要是觉得不好，我就可以改成<code>/www/wwwroot/fanhua</code>这个样子。但是<strong>最好是使用域名作为根目录名称</strong>，比如<code>xxx.top</code>。</p>
<p>（3）<code>FTP</code>，我是创建了一个，虽然现在还不知道有什么用；</p>
<p>（4）数据库，我也是选择创建了一个，虽然现在也是不知道有什么用处；</p>
<p>（5）剩下的选择默认就好啦。</p>
<p>当填写完毕后，点击提交，会提示成功创建站点，如下图所指示：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612161724110.png" alt="image-20220612161724110" style="zoom:33%;" />

<p>【注意】后来发现，若是申请的视乎没有填写域名的话，自己自定义了一个目录名称，这可能会导致可以正常访问网页，但是<code>CSS</code>和<code>JS</code>等缺失的问题，所以这里最好还是使用自己的域名来作为目录比较好。其实理论上来说，应该是可以自定义才对，但是我还不知道怎么搞，后边知道了再补充。</p>
<h2 id="7-上传网站源码"><a href="#7-上传网站源码" class="headerlink" title="7. 上传网站源码"></a><font size=3>7. 上传网站源码</font></h2><p>接下来，我们就要上传自己网站的网站源码啦，我是用的<code>Hexo</code>生成的静态博客站点，所以我只需要上传博客站点目录下的<code>public</code>文件夹下的所有文件就好啦。</p>
<h2 id="7-1-删除默认生成的文件"><a href="#7-1-删除默认生成的文件" class="headerlink" title="7.1 删除默认生成的文件"></a><font size=3>7.1 删除默认生成的文件</font></h2><p>首先我们点击创建的站点中的根目录选项：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612162632908.png" alt="image-20220612162632908" style="zoom:33%;" />

<p>然后就会打开这个根目录，下边默认的文件如下图，我们全部删掉即可：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612162742024.png" alt="image-20220612162742024" style="zoom:33%;" />

<p>选中后，右键删除即可，最后还会剩下一个<code>.user.ini</code>是全选的时候没有删掉的，我们可以再单独选中就可以删除了，这个文件目前还不知道有什么用，我自己删掉后再上传是没什么问题的。</p>
<h3 id="7-2-上传文件"><a href="#7-2-上传文件" class="headerlink" title="7.2 上传文件"></a><font size=3>7.2 上传文件</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612163221518.png" alt="image-20220612163221518" style="zoom:33%;" />

<p>点击上传就可以上传文件了，这里上传的话是上传的目录或者是文件，个人觉得不太方便，这里我就先上传一个主页的文件，用于测试，后边会在本地端直接推送文件到这个目录下的。</p>
<h2 id="8-IP访问网站"><a href="#8-IP访问网站" class="headerlink" title="8. IP访问网站"></a><font size=3>8. <code>IP</code>访问网站</font></h2><p>上传完毕后，就该访问啦，怎么访问呢？我们还没有域名呢，当然也是支持的啦，我们可以通过 <code>IP</code>地址<code>+</code>端口 来访问的，我们有<code>IP</code>地址，但是端口好像还没有设置，接下来就来看看怎么弄吧</p>
<ul>
<li>方法一：</li>
</ul>
<p>还记的建站的时候，让输入域名，其实这里我们直接输入自己的服务器的<code>IP</code>也是可以的，也就是说，我们可以输入：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">xxx.xxx.xxx.xxx:port</span><br></pre></td></tr></table></figure>

<p><code>port</code>就代表端口号。</p>
<ul>
<li>方法二</li>
</ul>
<p>我们已经创建过了啊，这怎么办呢，还可以在这里添加：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612163850916.png" alt="image-20220612163850916" style="zoom:33%;" />

<p>然后，我们就进入了站点的设置选项面板中：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612164026730.png" alt="image-20220612164026730" style="zoom: 50%;" />

<p>端口嘛，我好像还不知道有什么限制，但是我学习网络编程的时候，了解到用户使用的最好就是<code>5000</code>往后，所以我就设置的<code>5200</code>啦。然后，我们就可以通过以下格式来访问网站啦：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">xxx.xxx.xxx.xxx:5200</span><br></pre></td></tr></table></figure>

<p>但是，很遗憾，无法访问，具体原因不清楚，只好改回默认的<code>80</code>端口啦，这下就可以了，那就修改访问格式如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">xxx.xxx.xxx.xxx:80</span><br></pre></td></tr></table></figure>

<p>然后就可以看到这样一个页面啦：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV05-%E9%83%A8%E7%BD%B2%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8-02-%E9%83%A8%E7%BD%B2%E7%BD%91%E7%AB%99/img/image-20220612164951206.png" alt="image-20220612164951206" style="zoom:33%;" />

<p>由于只上传了网站的主页文件，所以显示出来就很不正常，后边通过服务器的配置，就可以正常显示网页啦。</p>
<h2 id="9-域名访问网站"><a href="#9-域名访问网站" class="headerlink" title="9. 域名访问网站"></a><font size=3>9. 域名访问网站</font></h2><p>我们创建网站不能只用<code>IP</code>访问吧，我们使用域名的话，怎么办呢？</p>
<p>首先，域名一定要解析到自己的服务器的<code>IP</code>，然后我们像上边一样，在站点设置的域名管理中添加一个域名，按下边的格式，使用泛解析：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">*.xxx.com</span><br></pre></td></tr></table></figure>

<p>总之就是自己的域名前边加一个<code>*.</code>就好啦，不要直接使用域名，而什么前缀都没有，那样无法访问的。</p>
<h1 id="三、服务器端"><a href="#三、服务器端" class="headerlink" title="三、服务器端"></a><font size=3>三、服务器端</font></h1><p>接下来就是服务器端的配置了，其实服务器端需要解决的就是如何接收<code>Win</code>本地端推送的数据。</p>
<h2 id="1-Git的安装"><a href="#1-Git的安装" class="headerlink" title="1. Git的安装"></a><font size=3>1. <code>Git</code>的安装</font></h2><p>其实服务器在创建的时候就自动安装了<code>Git</code>工具，若是没有的话，可以直接去官网搜一下就好啦，这里就不再赘述怎么安装配置了，本篇文章的目的也不在这里。这里很多的操作都需要使用<code>root</code>权限，所以我们可以先切换到<code>root</code>权限下，输入以下命令吗，然后输入密码就可以切换到<code>root</code>啦。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">su</span><br></pre></td></tr></table></figure>

<h2 id="2-添加新用户git"><a href="#2-添加新用户git" class="headerlink" title="2. 添加新用户git"></a><font size=3>2. 添加新用户<code>git</code></font></h2><h3 id="2-1-创建用户"><a href="#2-1-创建用户" class="headerlink" title="2.1 创建用户"></a><font size=3>2.1 创建用户</font></h3><p>我们新创建一个<code>git</code>用户来作为我们使用<code>git</code>的地方，我们在终端输入以下命令</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">adduser git</span><br></pre></td></tr></table></figure>

<p>然后我们按照提示，输入两次要设置的用户密码，其他的全部默认就可以了：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">Adding user `git&#x27; ...</span><br><span class="line">Adding new group `git&#x27; (1004) ...</span><br><span class="line">Adding new user `git&#x27; (1004) with group `git&#x27; ...</span><br><span class="line">Creating home directory `/home/git&#x27; ...</span><br><span class="line">Copying files from `/etc/skel&#x27; ...</span><br><span class="line">New password: </span><br><span class="line">Retype new password: </span><br><span class="line">passwd: password updated successfully</span><br><span class="line">Changing the user information for git</span><br><span class="line">Enter the new value, or press ENTER for the default</span><br><span class="line">        Full Name []: </span><br><span class="line">        Room Number []: </span><br><span class="line">        Work Phone []: </span><br><span class="line">        Home Phone []: </span><br><span class="line">        Other []: </span><br><span class="line">Is the information correct? [Y/n] Y</span><br></pre></td></tr></table></figure>

<h3 id="2-2-设置git用户权限"><a href="#2-2-设置git用户权限" class="headerlink" title="2.2 设置git用户权限"></a><font size=3>2.2 设置<code>git</code>用户权限</font></h3><h4 id="2-2-1-sudoers文件"><a href="#2-2-1-sudoers文件" class="headerlink" title="2.2.1 sudoers文件"></a><font size=3>2.2.1 <code>sudoers</code>文件</font></h4><details class="folding-tag" blue><summary> 点击查看 sudoers 文件说明 </summary>
              <div class='content'>
              <p>有一个文件，是<code>/etc/sudoers</code>，该文件允许特定用户像<code>root</code>用户一样使用各种各样的命令，而不需要<code>root</code>用户的密码，例如，该文件下中这么一行：</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">root    ALL=(ALL:ALL) ALL</span><br></pre></td></tr></table></figure><p>在网上找到了一个解释：</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">The first field indicates the username that the rule will apply to (root).</span><br><span class="line">First “ALL” indicates that this rule applies to all hosts.</span><br><span class="line">Second “ALL” indicates that the root user can run commands as all users.</span><br><span class="line">Third “ALL” indicates that the root user can run commands as all groups.</span><br><span class="line">Forth “ALL” indicates these rules apply to all commands.</span><br></pre></td></tr></table></figure><p>翻译过来其实就是说</p><ul><li><code>root</code>表示用户账号，也就是我们想要配置的让哪个系统帐号可以使用<code>sudo</code>命令；</li><li>第一个<code>ALL</code>表示此规则适用于所有主机，意思就是允许用户从哪些地方连接到这台主机，<code>linux</code>作为服务器，管理员是有可能从别的主机远程连接过来的;</li><li>第二个<code>ALL</code>表示<code>root</code>用户可以以所有用户的身份执行命令。</li><li>第三个<code>ALL</code>表示<code>root</code>用户可以作为所有组运行命令。</li><li>第四个<code>ALL</code>表示这些规则适用于所有命令。</li></ul>
              </div>
            </details>

<h4 id="2-2-2-修改用户权限"><a href="#2-2-2-修改用户权限" class="headerlink" title="2.2.2 修改用户权限"></a><font size=3>2.2.2 修改用户权限</font></h4><ul>
<li>改变<code>sudoers</code>文件的权限为文件所有者可写</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod 740 /etc/sudoers</span><br></pre></td></tr></table></figure>

<ul>
<li>编辑文件</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/sudoers</span><br></pre></td></tr></table></figure>

<p>找到这一行：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">root    ALL=(ALL:ALL) ALL</span><br></pre></td></tr></table></figure>

<p>在这一行下边添加以下内容：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git    ALL=(ALL:ALL) ALL</span><br></pre></td></tr></table></figure>

<ul>
<li>将<code>sudoers</code>权限修改为文件所有者可读</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod 400 /etc/sudoers</span><br></pre></td></tr></table></figure>

<h2 id="3-添加SSH公钥"><a href="#3-添加SSH公钥" class="headerlink" title="3. 添加SSH公钥"></a><font size=3>3. 添加<code>SSH</code>公钥</font></h2><p>我们要将文件从<code>Windows</code>本地端通过<code>git</code>上传到服务器的话，就需要将<code>Windows</code>本地的公钥添加到服务器中。之前我们一直处于<code>root</code>用户，现在我们切换到<code>git</code>用户：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">su git  # 切换到git用户</span><br><span class="line">cd ~    # 回到git用户的家目录</span><br></pre></td></tr></table></figure>

<ul>
<li>创建<code>.ssh</code>目录</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mkdir -p ~/.ssh</span><br></pre></td></tr></table></figure>

<ul>
<li>创建<code>authorized\_keys</code>文件</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">touch ~/.ssh/authorized_keys  # 创建authorized_keys文件</span><br></pre></td></tr></table></figure>

<ul>
<li>为<code>authorized_keys</code>文件赋予文件所有者可读可写的权限</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod 600 ~/.ssh/authorized_keys</span><br></pre></td></tr></table></figure>

<ul>
<li>添加<code>Win</code>本地端<code>SSH</code>公钥</li>
</ul>
<p>然后就是打开这个文件，将<code>Win</code>中<code>C:\Users\用户名\.ssh</code>路径下<code>id_rsa.pub</code>公钥文件的内容复制到服务器端刚才创建的<code>authorized_keys</code>文件中。</p>
<ul>
<li>修改服务器端<code>.ssh</code>目录权限</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod 700 ~/.ssh  # 修改.ssh目录所有者可读可写可执行的权限</span><br></pre></td></tr></table></figure>

<ul>
<li>测试<code>Win</code>本地端是否可以免密链接到服务器</li>
</ul>
<p>在<code>Win</code>本地端的<code>Git bash</code>中执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh -v git@server_IP</span><br></pre></td></tr></table></figure>

<p>若可以成功连接，将会显示以下信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">OpenSSH_8.8p1, OpenSSL 1.1.1m  14 Dec 2021</span><br><span class="line">debug1: Reading configuration data /etc/ssh/ssh_config</span><br><span class="line">debug1: Connecting to 43.142.124.212 [43.142.124.212] port 22.</span><br><span class="line">debug1: Connection established.</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">后边的省略 ... ...</span></span><br></pre></td></tr></table></figure>

<h2 id="4-创建Git仓库"><a href="#4-创建Git仓库" class="headerlink" title="4. 创建Git仓库"></a><font size=3>4. 创建<code>Git</code>仓库</font></h2><p>此部分均在<code>git</code>用户下完成。</p>
<h3 id="4-1-创建裸仓库"><a href="#4-1-创建裸仓库" class="headerlink" title="4.1 创建裸仓库"></a><font size=3>4.1 创建裸仓库</font></h3><ul>
<li>创建仓库位置</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo mkdir /home/git/repos</span><br></pre></td></tr></table></figure>

<ul>
<li>初始化一个裸仓库</li>
</ul>
<p>裸仓库其实就相当于我们使用<code>git init</code>初始化仓库后，仓库中的<code>.git</code>目录，裸仓库是不能存储文件的，上传的文件也不会在裸仓库出现，所以后边需要使用钩子函数进行一个自动的部署。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd /home/git/repos</span><br><span class="line">sudo git init --bare fanhua.git # 初始化一个名叫fanhua的裸仓库</span><br></pre></td></tr></table></figure>

<p>初始化完成后会有如下提醒：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Initialized empty Git repository in /home/git/repos/fanhua.git/</span><br></pre></td></tr></table></figure>

<h3 id="4-2-添加钩子函数"><a href="#4-2-添加钩子函数" class="headerlink" title="4.2 添加钩子函数"></a><font size=3>4.2 添加钩子函数</font></h3><p>这一步需要创建一个钩子函数，以完成自动部署。当我们将本地的数据推送上来的时候可以自动将文件放入<code>/www/wwwroot/hexo</code>下，也就是将上传的文件放到我们在宝塔面板创建的网站根目录中。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd /home/git/repos/fanhua.git/hooks  # 进入裸仓库的钩子函数目录</span><br><span class="line">sudo post-update</span><br></pre></td></tr></table></figure>

<p>编辑<code>post-update</code>文件并添加以下内容并保存：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">!/bin/sh</span></span><br><span class="line">git --work-tree=/www/wwwroot/hexo --git-dir=/home/git/repos/fanhua.git checkout -f</span><br></pre></td></tr></table></figure>

<h2 id="5-修改相关文件权限"><a href="#5-修改相关文件权限" class="headerlink" title="5. 修改相关文件权限"></a><font size=3>5. 修改相关文件权限</font></h2><h3 id="5-1-修改钩子函数权限"><a href="#5-1-修改钩子函数权限" class="headerlink" title="5.1 修改钩子函数权限"></a><font size=3>5.1 修改钩子函数权限</font></h3><p>我们需要赋予钩子函数可执行的权限，以保证钩子函数的运行。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd /home/git/repos/fanhua.git/hooks  # 进入裸仓库的钩子函数目录</span><br><span class="line"></span><br><span class="line">sudo chmod +x post-update  # 赋予钩子函数文件可执行权限</span><br></pre></td></tr></table></figure>

<h3 id="5-2-修改裸仓库权限"><a href="#5-2-修改裸仓库权限" class="headerlink" title="5.2 修改裸仓库权限"></a><font size=3>5.2 修改裸仓库权限</font></h3><p>需要将<code>git</code>裸仓库的所有者改为<code>git</code>用户。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo chown -R git:git /home/git/repos / # 仓库所有者改为git</span><br></pre></td></tr></table></figure>

<h3 id="5-3-修改网站根目录权限"><a href="#5-3-修改网站根目录权限" class="headerlink" title="5.3 修改网站根目录权限"></a><font size=3>5.3 修改网站根目录权限</font></h3><p>我们需要将站点根目录的所有者改为<code>git</code>用户：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo chown -R git:git /www/wwwroot/hexo/ # 站点目录所有者改为git</span><br></pre></td></tr></table></figure>

<p>如果说，我们之前在宝塔面板将站点根目录的文件删除的干干净净，那么，这里是不会有问题的，若是没有删除，则执行上边这条命令的时候可能会报以下错误（我又建了一个<code>1.1.1.1</code>的根目录来测试）：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chown: changing ownership of &#x27;/www/wwwroot/1.1.1.1/.user.ini&#x27;: Operation not permitted</span><br></pre></td></tr></table></figure>

<p>出现这个问题的话，是<code>.user.ini</code>这个文件的问题，一种方式就是去宝塔面板删除这个文件，另一种处理方法就是执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sudo chattr -i /www/wwwroot/网站根目录/.user.ini</span><br><span class="line"></span><br><span class="line">sudo chattr -i /www/wwwroot/1.1.1.1/.user.ini</span><br></pre></td></tr></table></figure>

<p>然后再修改根目录所有者就可以啦。</p>
<h2 id="6-测试是否可以拉取裸仓库"><a href="#6-测试是否可以拉取裸仓库" class="headerlink" title="6. 测试是否可以拉取裸仓库"></a><font size=3>6. 测试是否可以拉取裸仓库</font></h2><p>我们在<code>Git Bash</code>中执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone git@server_ip:/home/git/repos/fanhua.git</span><br></pre></td></tr></table></figure>

<p>首次下载的话，可能会有如下提示：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">Cloning into &#x27;fanhua&#x27;...</span><br><span class="line">The authenticity of host &#x27;xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)&#x27; can&#x27;t be established.</span><br><span class="line">ED25519 key fingerprint is SHA256:huwVsfdbTiVhHBlVzuy8UU+/OWOoDvwWmu/E0DBOHdc.</span><br><span class="line">This key is not known by any other names</span><br><span class="line">Are you sure you want to continue connecting (yes/no/[fingerprint])? yes</span><br></pre></td></tr></table></figure>

<p>正常输入<code>yes</code>就可以了，若是下载成功，会有如下提示：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">warning: You appear to have cloned an empty repository.</span><br></pre></td></tr></table></figure>

<p>然后就会发现，在当前目录下出现了一个叫<code>fanhua</code>的目录，这就是我们拉取的仓库啦。</p>
<p>但是还有一种情况，就是之前服务器配置过裸仓库，但是后来重装服务器重新配置了裸仓库，那么这个时候下载的时候可能会有如下警告：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">Cloning into &#x27;fanhua&#x27;...</span><br><span class="line">@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@</span><br><span class="line">@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @</span><br><span class="line">@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@</span><br><span class="line">IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!</span><br><span class="line">Someone could be eavesdropping on you right now (man-in-the-middle attack)!</span><br><span class="line">It is also possible that a host key has just been changed.</span><br><span class="line">The fingerprint for the ED25519 key sent by the remote host is</span><br><span class="line">SHA256:huwVsfdbTiVhHBlVzuy8UU+/OWOoDvwWmu/E0DBOHdc.</span><br><span class="line">Please contact your system administrator.</span><br><span class="line">Add correct host key in /c/Users/20380/.ssh/known_hosts to get rid of this message.</span><br><span class="line">Offending ECDSA key in /c/Users/20380/.ssh/known_hosts:8</span><br><span class="line">Host key for xxx.xxx.xxx.xxx has changed and you have requested strict checking.</span><br><span class="line">Host key verification failed.</span><br><span class="line">fatal: Could not read from remote repository.</span><br><span class="line"></span><br><span class="line">Please make sure you have the correct access rights</span><br><span class="line">and the repository exists.</span><br></pre></td></tr></table></figure>

<p>大概就是说<code>/c/Users/20380/.ssh/known_hosts</code>文件有问题，我嘛处理方式简单，直接删除，然后重新下载即可。</p>
<h2 id="7-推送文件"><a href="#7-推送文件" class="headerlink" title="7. 推送文件"></a><font size=3>7. 推送文件</font></h2><p>既然拉取成功了，那么我们来试一下推送文件上去：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd fanhua/</span><br><span class="line">touch test.html</span><br></pre></td></tr></table></figure>

<p>然后我们就可以正常提交：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git add .</span><br><span class="line">git commit -m &quot;test&quot;</span><br><span class="line">git push -u origin master</span><br></pre></td></tr></table></figure>

<p>显示以下信息表示推送成功：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">Enumerating objects: 3, done.</span><br><span class="line">Counting objects: 100% (3/3), done.</span><br><span class="line">Writing objects: 100% (3/3), 201 bytes | 201.00 KiB/s, done.</span><br><span class="line">Total 3 (delta 0), reused 0 (delta 0), pack-reused 0</span><br><span class="line">To 43.142.124.212:/home/git/repos/fanhua.git</span><br><span class="line"> * [new branch]      master -&gt; master</span><br><span class="line">branch &#x27;master&#x27; set up to track &#x27;origin/master&#x27;.</span><br></pre></td></tr></table></figure>

<ul>
<li><code>/www/wwwroot/hexo</code>目录情况</li>
</ul>
<p>在任意一个用户中执行以下命令均可</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ls /www/wwwroot/hexo/</span><br></pre></td></tr></table></figure>

<p>然后会看到如下信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">index.html  test.html</span><br></pre></td></tr></table></figure>

<p>第一个文件使我们使用宝塔面板上传的文件，第二个就是我们刚才用<code>git</code>上传的文件啦。</p>
<ul>
<li><code>git</code>用户下的裸仓库</li>
</ul>
<p>我们再来看一看裸仓库，需要先切换到<code>git</code>用户：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">su git</span><br><span class="line">ls ~/repos/fanhua.git/</span><br></pre></td></tr></table></figure>

<p>然后会看到如下信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">branches  config  description  HEAD  hooks  index  info  objects  refs</span><br></pre></td></tr></table></figure>

<p>发现此目录下并没有刚才上传的<code>git</code>文件。由此说明，钩子函数确实发挥了作用，文件被上传到我们希望的目录去了。</p>
<h1 id="四、Hexo站点的配置"><a href="#四、Hexo站点的配置" class="headerlink" title="四、Hexo站点的配置"></a><font size=3>四、<code>Hexo</code>站点的配置</font></h1><p>最后就是我们如何在本地将<code>hexo</code>站点中的目标文件夹，也就是<code>public</code>文件中的目录推送到我们的服务器网站根目录啦，我们后来都是使用的<code>Github Action</code>来完成自动化的部署，应该还记得<code>hexo</code>有一个一键部署的<code>hexo d</code>命令吧。</p>
<h2 id="1-安装一键部署工具"><a href="#1-安装一键部署工具" class="headerlink" title="1. 安装一键部署工具"></a><font size=3>1. 安装一键部署工具</font></h2><p>进入本地<code>Hexo</code>站点根目录，执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-deployer-git --save</span><br></pre></td></tr></table></figure>

<h2 id="2-配置站点配置文件"><a href="#2-配置站点配置文件" class="headerlink" title="2. 配置站点配置文件"></a><font size=3>2. 配置站点配置文件</font></h2><p>编辑<code>[blogRoot]/_config.yml</code>，修改<code>deploy</code>部分如下：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">deploy:</span></span><br><span class="line">  <span class="attr">type:</span> <span class="string">git</span></span><br><span class="line">  <span class="attr">repo:</span> <span class="string">git@server_ip:/home/git/repos/fanhua.git</span></span><br><span class="line">  <span class="attr">branch:</span> <span class="string">master</span></span><br></pre></td></tr></table></figure>

<h2 id="3-一键部署"><a href="#3-一键部署" class="headerlink" title="3. 一键部署"></a><font size=3>3. 一键部署</font></h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo d</span><br></pre></td></tr></table></figure>



<h1 id="五、效果预览"><a href="#五、效果预览" class="headerlink" title="五、效果预览"></a><font size=3>五、效果预览</font></h1><p>到此为止，配置全部完成，除了域名没有安排上之外，其他的都已配置完成，我们可以通过<code>IP:port</code>的形式访问我们的网站啦，效果如下嘛，后续就访问我的域名直接查看好啦.</p>

    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/beeb17ce.html">LV05-部署云服务器-02-部署网站</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2023年07月02日 - 16:17</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/beeb17ce.html" title="LV05-部署云服务器-02-部署网站">https://sumumm.github.io/post/beeb17ce.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" rel="tag"><i class="fa fa-tag"></i> 博客搭建</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/d2eb46ea.html" rel="prev" title="LV05-01-进程-01-进程的基础知识">
                  <i class="fa fa-angle-left"></i> LV05-01-进程-01-进程的基础知识
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/c5b8cba6.html" rel="next" title="LV05-部署云服务器-01-登录服务器">
                  LV05-部署云服务器-01-登录服务器 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">false</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
